require( '$d/css/common.less' );
require('./style.less');
define( [
  'jquery',
  'require',
  'message',
  'api',
  'bootstrap',
  'constants',
  'login'
], function( $, require ) {
  var ShowTitleMessage = require( 'message' ),
    showTime = ShowTitleMessage.showTime,
    BIGWE_API = require( 'api' );

  var login = require( 'login' );
  var c = require( 'constants' );
  //邮箱验证
  //var emailRe=/^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
  var emailRe = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  //手机号验证
  var re = /^1[3,4,5,7,8]{1}[0-9]{9}$/;
  //验证码验证
  var codeRe = /^[A-Za-z0-9]+$/;
  //密码验证
  var pwdRe = /^[a-zA-Z0-9_\.\-]{6,20}$/;

  /**
   * 容错  在某些改了domain的页面会造成跨域错误
   * @return {[type]}
   */
  ! function() {
    var dom = null;
    try {
      dom = window.top.document;
    } catch ( e ) {
      document.domain = 'bigwe.com';
      dom = window.top.document;
    }
    $( '#register-guide .spinner', dom ).remove();
  }();
  $( document ).ready( function() {
    //跳过按钮
    //邮箱登陆跳转链接数组
    var hash = {
      'qq.com': 'http://mail.qq.com',
      'gmail.com': 'http://mail.google.com',
      'sina.com': 'http://mail.sina.com.cn',
      '163.com': 'http://mail.163.com',
      '126.com': 'http://mail.126.com',
      'yeah.net': 'http://www.yeah.net/',
      'sohu.com': 'http://mail.sohu.com/',
      'tom.com': 'http://mail.tom.com/',
      'sogou.com': 'http://mail.sogou.com/',
      '139.com': 'http://mail.10086.cn/',
      'hotmail.com': 'http://www.hotmail.com',
      'live.com': 'http://login.live.com/',
      'live.cn': 'http://login.live.cn/',
      'live.com.cn': 'http://login.live.com.cn',
      '189.com': 'http://webmail16.189.cn/webmail/',
      'yahoo.com.cn': 'http://mail.cn.yahoo.com/',
      'yahoo.cn': 'http://mail.cn.yahoo.com/',
      'eyou.com': 'http://www.eyou.com/',
      '21cn.com': 'http://mail.21cn.com/',
      '188.com': 'http://www.188.com/',
      'foxmail.com': 'http://www.foxmail.com'
    };

    //验证码刷新
    $( '.verify_img img' ).click( function() {
      $( this ).attr( "src", "/RegisterPage/captcha" );
    } );
    //绑定账号按钮
    $( '.bind-button' ).click( function() {
      $.ajax( {
        cache: true,
        type: "POST", //用POST方式传输
        dataType: 'text',
        url: BIGWE_API.REGISTER.BIND_BIGWE, //目标地址
        data: {
          user_account: $( '#user_account' ).val(),
          user_password: $( '#user_password' ).val(),
          user_verify: $( '#verify-code' ).val()
        },
        error: function() {
          ShowTitleMessage.showWarning( '账号查询失败', showTime );
        },
        success: function( msg ) {
          msg = $.parseJSON( msg );
          if ( !msg.ret ) {

            $( '#code_check' ).attr( 'src', c.resPath + '/images/right_logo.png' );
            $( '#code_check' ).show();
            $( '#account_check' ).attr( 'src', c.resPath + '/images/right_logo.png' );
            $( '#account_check' ).show();
            $( '#pwd_check' ).attr( 'src', c.resPath + '/images/right_logo.png' );
            $( '#pwd_check' ).show();
            $( ".bind-bigwe  > li" ).eq( 0 ).hide();
            $( ".bind-bigwe  > li" ).eq( 1 ).show();
            $( '#register-guide .skip', window.top.document ).hide();
            $( '.js_register_guide', window.top.document ).removeClass( 'js_register_guide' );
            // 页面数据刷新
            login.refreshUserInfo( msg.data );
          } else {
            ShowTitleMessage.showWarning( msg.msg, showTime );;
            if ( msg == 40010 ) {
              $( '#account_check' ).attr( 'src', c.resPath + '/images/error_logo.png' );
              $( '#account_check' ).show();

            } else if ( msg == 40020 ) {
              $( '#account_check' ).attr( 'src', c.resPath + '/images/error_logo.png' );
              $( '#account_check' ).show();
            } else if ( msg == 40021 ) {

              $( '#account_check' ).attr( 'src', c.resPath + '/images/right_logo.png' );
              $( '#account_check' ).show();
              $( '#pwd_check' ).attr( 'src', c.resPath + '/images/error_logo.png' );
              $( '#pwd_check' ).show();
            } else if ( msg == 40040 ) {

              $( '#account_check' ).attr( 'src', c.resPath + '/images/right_logo.png' );
              $( '#account_check' ).show();
              $( '#pwd_check' ).attr( 'src', c.resPath + '/images/right_logo.png' );
              $( '#pwd_check' ).show();
              $( '#code_check' ).attr( 'src', c.resPath + '/images/error_logo.png' );
              $( '#code_check' ).show();
            } else if ( msg == 40045 ) {
              $( '#account_check' ).attr( 'src', c.resPath + '/images/right_logo.png' );
              $( '#account_check' ).show();
              $( '#pwd_check' ).attr( 'src', c.resPath + '/images/right_logo.png' );
              $( '#pwd_check' ).show();
              $( '#code_check' ).attr( 'src', c.resPath + '/images/error_logo.png' );
              $( '#code_check' ).show();
              $( ".verify-img img" ).trigger( 'click' );
            } else if ( msg == 40046 ) {
              $( '#account_check' ).attr( 'src', c.resPath + '/images/right_logo.png' );
              $( '#account_check' ).show();
              $( '#pwd_check' ).attr( 'src', c.resPath + '/images/error_logo.png' );
              $( '#pwd_check' ).show();
            } else {

            }
          }
        }
      } )
    } );

    //前往微知按钮
    $( '.jump-bigwe' ).click( function() {
      $( '.guide_main' ).hide();
      window.top.registerGuideToggle();
    } );

    //跳回绑定微知账号页面
    // $('.bind-field').click(function(){
    //     $(".bind-bigwe  > li").eq(1).hide();
    //     $(".bind-bigwe  > li").eq(0).show();
    // });

    // $('.bind-email,.bind-phone').click(function(){
    //     $(".bind-bigwe  > li").eq(3).hide();
    //     $(".bind-bigwe  > li").eq(0).show();
    // });

    // $('.bind-detailed').click(function(){
    //     $(".bind-bigwe  > li").eq(5).hide();
    //     $(".bind-bigwe  > li").eq(0).show();
    // });

    //注册微知账号按钮
    $( '.register-button' ).click( function() {
      $( ".bind-bigwe  > li" ).eq( 0 ).hide();
      $( ".bind-bigwe  > li" ).eq( 2 ).show();
      $( '#register-guide .skip', window.top.document ).text( '暂不注册' );
    } );

    //微知协议勾选
    $( ".register > button" ).attr( "disabled", "disabled" );
    $( ".checkbox" ).change( function() {
      console.log( $( this ).prop( "checked" ) );
      if ( $( this ).prop( "checked" ) ) {
        $( this ).parent().siblings( "button" ).css( 'background-color', '#44B549' );
        $( this ).parent().siblings( "button" ).removeAttr( 'disabled' );
      } else {
        $( this ).parent().siblings( "button" ).css( 'background-color', '#c7c7c7' );
        $( this ).parent().siblings( "button" ).attr( "disabled", "disabled" );
      }
    } );

    //手机号邮箱注册操作
    $( ".register" ).on( "click", "#phone_button", function() {
      var phone = $( "#user_phone" ).val();
      var code = $( "#verify_code" ).val();
      if ( $( '#user_phone' ).val() == '' ) {
        $( '.fontred_phone' ).html( '必填项' );
        $( '.phone_right' ).hide();
      }
      if ( $( '#verify_code' ).val() == '' ) {
        $( '.fontred_verify' ).html( '请输入手机验证码' );
        $( '.verify_right' ).hide();
      }
      if ( $( '#phone_user_pwd' ).val() == '' ) {
        $( '#phone_user_pwd' ).siblings( '.pwd_right' ).hide();
        $( '#phone_user_pwd' ).siblings( '.fontred_pwd' ).html( '必填项' );
      }
      if ( $( '#phone_user_name' ).val() == '' ) {
        $( '#phone_user_name' ).siblings( '.name_right' ).hide();
        $( '#phone_user_name' ).siblings( '.fontred_name' ).html( '必填项' );
      }
      var _text = $( '.register-phone .item .fontred_warning' ).text();
      if ( _text != '' ) {
        return;
      }
      //手机号、昵称、邀请码验证
      $.ajax( {
        cache: true,
        type: "POST", //用POST方式传输
        dataType: 'text',
        url: BIGWE_API.REGISTER.NICENAME_VERIFY, //目标地址
        data: {
          user_name: $( '#phone_user_name' ).val()
        },
        success: function( msg ) {
          if ( msg == 'success' ) {
            //手机号
            $.ajax( {
              cache: true,
              type: "POST", //用POST方式传输
              dataType: 'json',
              url: BIGWE_API.REGISTER.VERIFY_VALID_CODE, //目标地址
              data: {
                account: phone,
                valid_code: code
              },
              error: function() {
                ShowTitleMessage.showWarning( '手机号/邮箱查询失败', showTime );
              },
              success: function( data ) {
                if ( data.ret == 0 ) {
                  $( '.fontred_verify' ).html( '' );
                  $( '.verify_right' ).show();
                  //邀请码
                  if ( $( '.user_invitation' ).val() != '' ) {
                    $.ajax( {
                      cache: true,
                      type: "POST", //用POST方式传输
                      dataType: 'text',
                      url: BIGWE_API.REGISTER.INVITATION_VERIFY, //目标地址
                      data: {
                        user_invitation: $( '.user_invitation' ).val()
                      },
                      error: function() {
                        ShowTitleMessage.showWarning( '输入的邀请码有误', showTime );
                      },
                      success: function( msg ) {
                        switch ( msg ) {
                          case 'error_invitation_null':
                            $( '.fontred_invitation' ).html( '邀请码不存在' );
                            $( '.invitation_right' ).hide();
                            break;
                          case 'error_invitation_invalid':
                            $( '.fontred_invitation' ).html( '邀请码失效' );
                            $( '.invitation_right' ).hide();
                            break;
                          default:
                            //$('.send_email').hide();
                            $( '.invitation_right' ).hide();
                            //手机号注册
                            $.ajax( {
                              cache: true,
                              type: "POST", //用POST方式传输
                              dataType: 'text',
                              url: BIGWE_API.REGISTER.REGISTER_VERIFY, //目标地址
                              data: {
                                account: $( '#user_phone' ).val(),
                                user_name: $( '#phone_user_name' ).val(),
                                user_pwd: $( '#phone_user_pwd' ).val(),
                                user_invitation: $( '#phone_user_invitation' ).val(),
                                valid_code: code,
                                action: 'bind',
                              },
                              error: function( msg ) {
                                ShowTitleMessage.showWarning( '注册失败', showTime );
                              },
                              success: function( msg ) {
                                /*msg = apinput(msg);
                                if(msg=='ok'){
                                    $('#register-guide').modal('hide');
                                    window.location.reload();
                                }*/
                                msg = typeof msg == 'object' ? msg : $.parseJSON( msg );
                                if ( !msg.ret ) {
                                  ShowTitleMessage.show( '注册成功', showTime );
                                  window.top.registerGuideToggle();
                                  login.refreshUserInfo( msg.data );
                                } else {
                                  ShowTitleMessage.showWarning( msg.msg || '注册失败', showTime );
                                }
                              }
                            } );
                        }
                      }
                    } );
                  } else {
                    //手机号注册
                    $.ajax( {
                      cache: true,
                      type: "POST", //用POST方式传输
                      dataType: 'text',
                      url: BIGWE_API.REGISTER.REGISTER_VERIFY, //目标地址
                      data: {
                        account: $( '#user_phone' ).val(),
                        user_name: $( '#phone_user_name' ).val(),
                        user_pwd: $( '#phone_user_pwd' ).val(),
                        user_invitation: $( '#phone_user_invitation' ).val(),
                        valid_code: code,
                        action: 'bind',
                      },
                      error: function( msg ) {
                        ShowTitleMessage.showWarning( '注册失败', showTime );
                      },
                      success: function( msg ) {
                        msg = typeof msg == 'object' ? msg : $.parseJSON( msg );
                        if ( !msg.ret ) {
                          ShowTitleMessage.show( '注册成功', showTime );
                          window.top.registerGuideToggle();
                          login.refreshUserInfo( msg.data );
                        } else {
                          ShowTitleMessage.showWarning( msg.msg || '注册失败', showTime );
                        }
                      }
                    } );
                  }
                } else {
                  $( '.verify_right' ).hide();
                  $( '.fontred_verify' ).html( data.msg );
                }
              }
            } );
          } else {
            $( '.name_right' ).hide();
            $( '.register-phone .fontred_name' ).html( '该昵称已被使用' );
          }
        }
      } );
    } );

    //手机号内容鼠标检测
    $( '#user_phone' ).blur( function() {
      if ( $( '#user_phone' ).val() == '' ) {
        $( '.fontred_phone' ).html( '必填项' );
        $( '.phone_right' ).hide();

      } else {
        if ( re.test( $( '#user_phone' ).val() ) || emailRe.test( $( '#user_phone' ).val() ) ) {
          $( '.fontred_phone' ).html( '' );
          //$('.phone_right').show();
        } else {
          $( '.fontred_phone' ).html( '输入的手机号 / 邮箱有误' );
          $( '.phone_right' ).hide();
        }
      }
    } );
    //手机号内容键盘检测
    $( '#user_phone' ).keyup( function() {
      if ( $( '#user_phone' ).val() == '' ) {
        $( '.fontred_phone' ).html( '必填项' );
        $( '.phone_right' ).hide();

      } else {
        if ( re.test( $( '#user_phone' ).val() ) || emailRe.test( $( '#user_phone' ).val() ) ) {
          $( '.fontred_phone' ).html( '' );
          //$('.phone_right').show();
        } else {
          $( '.fontred_phone' ).html( '输入的手机号 / 邮箱有误' );
          $( '.phone_right' ).hide();
        }
      }
    } );

    //验证码内容鼠标检测
    $( '#verify_code' ).blur( function() {
      if ( $( '#verify_code' ).val() == '' ) {
        $( '.fontred_verify' ).html( '必填项' );
        $( '.verify_right' ).hide();
      } else {
        if ( !codeRe.test( $( '#verify_code' ).val() ) ) {
          $( '.fontred_verify' ).html( '输入的验证码有误' );
          $( '.verify_right' ).hide();
        } else {
          $( '.fontred_verify' ).html( '' );
        }
      }
    } );
    //验证码内容键盘检测
    $( '#verify_code' ).keyup( function() {
      if ( $( '#verify_code' ).val() == '' ) {
        $( '.fontred_verify' ).html( '必填项' );
        $( '.verify_right' ).hide();
      } else {
        if ( !codeRe.test( $( '#verify_code' ).val() ) ) {
          $( '.verify_right' ).hide();
          $( '.fontred_verify' ).html( '输入的验证码有误' );
        } else {
          $( '.fontred_verify' ).html( '' );
        }
      }
    } );

    //昵称内容的键盘检测
    $( '.user_name' ).blur( function() {
      if ( $( this ).val() == '' ) {
        $( this ).siblings( '.name_right' ).hide();
        $( this ).siblings( '.fontred_name' ).html( '必填项' );
      } else {
        if ( $( this ).val().length >= 2 && chkstrlen( $( this ).val() ) <= 20 ) {
          $.ajax( {
            cache: true,
            type: "POST", //用POST方式传输
            dataType: 'text',
            url: BIGWE_API.REGISTER.NICENAME_VERIFY, //目标地址
            data: {
              user_name: $( '#phone_user_name' ).val()
            },
            success: function( msg ) {
              if ( msg == 'success' ) {
                $( '.register-phone .name_right' ).show();
              } else {
                $( '.name_right' ).hide();
                $( '.register-phone .fontred_name' ).html( '该昵称已被使用' );
              }
            }
          } );
        }
      }
    } );
    $( '.user_name' ).keyup( function() {
      if ( $( this ).val() == '' ) {
        $( this ).siblings( '.name_right' ).hide();
        $( this ).siblings( '.fontred_name' ).html( '必填项' );
      } else {
        if ( $( this ).val().length < 2 ) {
          $( this ).siblings( '.name_right' ).hide();
          $( this ).siblings( '.fontred_name' ).html( '输入的名称格式有误' );
        } else if ( chkstrlen( $( this ).val() ) > 20 ) {
          $( this ).siblings( '.name_right' ).hide();
          $( this ).siblings( '.fontred_name' ).html( '输入的名称格式有误' );
        } else {
          $( this ).siblings( '.fontred_name' ).html( '' );
        }
      }
    } );

    //用户密码内容的键盘检测
    $( '.user_pwd' ).focus( function() {
      if ( $( this ).val() == '' ) {
        $( this ).siblings( '.fontred_pwd' ).html( '' );
        $( '.login-list .focus_tips' ).show();
      }
    } );
    $( '.user_pwd' ).blur( function() {
      if ( $( this ).val() == '' ) {
        $( this ).siblings( '.pwd_right' ).hide();
        $( this ).siblings( '.fontred_pwd' ).html( '必填项' );
        $( '.login-list .focus_tips' ).hide();
      }

    } );
    $( '.user_pwd' ).keyup( function() {
      $( '.login-list .focus_tips' ).hide();
      if ( $( this ).val() == '' ) {
        $( this ).siblings( '.pwd_right' ).hide();
        $( this ).siblings( '.fontred_pwd' ).html( '必填项' );
      } else {
        if ( $( this ).val().length < 6 ) {
          $( this ).siblings( '.pwd_right' ).hide();
          $( this ).siblings( '.fontred_pwd' ).html( '输入的密码格式有误' );
        } else {
          $( this ).siblings( '.fontred_pwd' ).html( '' );
          $( this ).siblings( '.pwd_right' ).show();

        }
      }
    } );
    //邀请码键盘检测
    $( '.user_invitation' ).focus( function() {
      if ( $( this ).val() == '' ) {
        $( this ).siblings( '.fontred_invitation' ).html( '' );
        $( '.login-list .focus_tips' ).show();
      }
    } );
    $( '.user_invitation' ).blur( function() {
      if ( $( this ).val() == '' ) {
        $( this ).siblings( '.invitation_right' ).hide();
        $( this ).siblings( '.fontred_invitation' ).html( '必填项' );
        $( '.login-list .focus_tips' ).hide();
      } else {
        $.ajax( {
          type: "POST", //用POST方式传输
          dataType: 'text',
          url: BIGWE_API.REGISTER.INVITATION_VERIFY, //目标地址
          data: {
            user_invitation: $( '.user_invitation' ).val()
          },
          error: function() {
            ShowTitleMessage.showWarning( '输入的邀请码有误', showTime );
          },
          success: function( msg ) {
            switch ( msg ) {
              case 'error_invitation_null':
                $( '.fontred_invitation' ).html( '邀请码不存在' );
                $( '.invitation_right' ).hide();
                break;
              case 'error_invitation_invalid':
                $( '.fontred_invitation' ).html( '邀请码失效' );
                $( '.invitation_right' ).hide();
                break;
              default:
                $( '.invitation_right' ).hide();
                $( '.fontred_invitation' ).html( '' );
            }
          }
        } );
      }
    } );
    $( '.user_invitation' ).keyup( function() {
      if ( $( this ).val() == '' ) {
        $( this ).siblings( '.invitation_right' ).hide();
        $( this ).siblings( '.fontred_invitation' ).html( '必填项' );
      } else {
        $( this ).siblings( '.fontred_invitation' ).html( '' );
      }
    } );
    //行业选择内容的检测
    $( '.field-title-choice' ).click( function() {
      $( '.fontred-field-choice' ).html( '' );
    } );

  } );
  //验证码发送
  var InterValObj; //timer变量，控制时间
  var reg_count = 60; //间隔函数，1秒执行
  var curCount; //当前剩余秒数
  function sendMessage() {
    var page_token = $( 'input#page_token' ).val();
    if ( re.test( $( '#user_phone' ).val() ) || emailRe.test( $( '#user_phone' ).val() ) ) {
      $( '.fontred_phone' ).html( '' );
      //设置button效果，开始计时
      if ( $( '#user_phone' ).val().indexOf( '@' ) != -1 ) {
        $.ajax( {
          cache: true,
          type: "POST", //用POST方式传输
          dataType: 'text',
          url: BIGWE_API.REGISTER.EMAIL_VERIFY, //目标地址
          data: {
            user_email: $( '#user_phone' ).val()
          },
          error: function() {
            ShowTitleMessage.showWarning( '邮箱查询失败', showTime );
          },
          success: function( msg ) {
            if ( msg == 'success' ) {
              $( '.fontred_phone' ).html( '' );
              $( ".get-code" ).attr( "disabled", "true" );
              $( ".get-code" ).css( 'background', '#ccc' );
              $.ajax( {
                cache: true,
                type: "POST", //用POST方式传输
                dataType: "text", //数据格式
                url: BIGWE_API.REGISTER.SEND_MAIL, //目标地址
                data: {
                  user_email: $( '#user_phone' ).val()
                },
                error: function( msg ) {
                  ShowTitleMessage.showWarning( '发送失败', showTime );
                },
                success: function( msg ) {
                  switch ( msg ) {
                    case 'email_over':
                      ShowTitleMessage.showWarning( '今日邮箱验证已用完', showTime );
                      $( ".get-code" ).removeAttr( "disabled" );
                      $( ".get-code" ).css( 'background', '' );
                      break;
                    case 'error_send':
                      curCount = reg_count;
                      $( ".get-code" ).val( curCount + "s后重新获取" );
                      InterValObj = window.setInterval( SetRemainTime, 1000 );
                      ShowTitleMessage.showWarning( '邮件发送失败', showTime );
                      break;
                    case 'success':
                      curCount = reg_count;
                      $( ".get-code" ).val( curCount + "s后重新获取" );
                      InterValObj = window.setInterval( SetRemainTime, 1000 );
                      ShowTitleMessage.show( '发送成功', showTime );
                      break;
                    default:
                      curCount = msg;
                      $( ".get-code" ).val( msg + "s后重新获取" );
                      InterValObj = window.setInterval( SetRemainTime, 1000 );
                      ShowTitleMessage.showWarning( '操作频繁，请稍后再试', showTime );
                      $( ".register > button" ).attr( "disabled", "disabled" );
                      break;
                  }
                }
              } );
            } else {
              $( '.fontred_phone' ).html( '该邮箱已注册' );
              $( '.phone_right' ).hide();
            }
          }
        } );
      } else {
        $.ajax( {
          cache: true,
          type: "POST", //用POST方式传输
          dataType: "text", //数据格式
          url: BIGWE_API.REGISTER.PHONE_VERIFY, //目标地址
          data: {
            user_phone: $( '#user_phone' ).val()
          },
          error: function() {
            ShowTitleMessage.showWarning( '手机号查询失败', showTime );
          },
          success: function( msg ) {
            if ( msg == 'success' ) {
              $( '.fontred_phone' ).html( '' );
              $( ".get-code" ).attr( "disabled", "true" );
              //$(".get-code").css('background','#ccc');
              //向后台发送处理数据
              $.ajax( {
                type: "POST", //用POST方式传输
                dataType: "json", //数据格式
                url: BIGWE_API.REGISTER.SEND_MESSAGE, //目标地址
                data: {
                  phone: $( '#user_phone' ).val(),
                  //sms_token:page_token,
                  verify: $( '#img_verify_code' ).val(),
                  page: 'guide'
                },
                error: function( data ) {
                  ShowTitleMessage.showWarning( '发送失败', showTime );
                },
                success: function( data ) {
                  switch ( data.ret ) {
                    case 41000:
                      //图片验证码错误ok
                      $( ".get-code" ).removeAttr( "disabled" );
                      ShowTitleMessage.showWarning( data.msg, showTime );
                      $( ".verify_img img" ).attr( "src", "/RegisterPage/captcha" );
                      break;
                    case 41001:
                      //请填写图片验证码ok
                      $( '#img_validate' ).modal( 'show' );
                      $( ".get-code" ).removeAttr( "disabled" );
                      //ShowTitleMessage.showWarning('请填写图片验证码', showTime);
                      break;
                    case 41003:
                      //今日短信验证码条数已用完ok
                      ShowTitleMessage.showWarning( data.msg, showTime );
                      $( '#img_validate' ).modal( 'hide' );
                      $( ".get-code" ).removeAttr( "disabled" );
                      $( '#img_verify_code' ).val( '' );
                      break;
                    case 41004:
                      //短信发送失败
                      curCount = reg_count;
                      $( ".get-code" ).val( curCount + "s后重新获取" );
                      InterValObj = window.setInterval( SetRemainTime, 1000 );
                      ShowTitleMessage.showWarning( data.msg, showTime );
                      $( '#img_validate' ).modal( 'hide' );
                      $( '#img_verify_code' ).val( '' );
                      break;
                    case 0:
                      //发送成功
                      curCount = reg_count;
                      $( ".get-code" ).val( curCount + "s后重新获取" );
                      InterValObj = window.setInterval( SetRemainTime, 1000 );
                      ShowTitleMessage.show( data.msg, showTime );
                      $( '#img_validate' ).modal( 'hide' );
                      $( '#img_verify_code' ).val( '' );
                      break;
                    case 41006:
                      //该手机号已被注册
                      ShowTitleMessage.showWarning( data.msg, showTime );
                      $( '#img_validate' ).modal( 'hide' );
                      $( ".get-code" ).removeAttr( "disabled" );
                      $( '#img_verify_code' ).val( '' );
                      break;
                    default:
                      //操作频繁，请稍后再试ok
                      curCount = data.data;
                      $( ".get-code" ).val( data.data + "s后重新获取" );
                      InterValObj = window.setInterval( SetRemainTime, 1000 );
                      ShowTitleMessage.showWarning( data.msg, showTime );
                      $( '#img_validate' ).modal( 'hide' );
                      $( ".register > button" ).attr( "disabled", "disabled" );
                      $( '#img_verify_code' ).val( '' );
                      break;
                  }
                }
              } );
            } else {
              $( '.phone_right' ).hide();
              $( '.fontred_phone' ).html( '该手机号已注册' );
            }
          }
        } );
      }

    } else {
      $( '.fontred_phone' ).html( '输入的手机号 / 邮箱有误' );
    }
  }
  $( '.get-code' ).click( function() {
    sendMessage();
  } );
  $( '#img_validate .btn-success' ).click( function() {
    if ( $( '#img_verify_code' ).val() == '' ) {
      ShowTitleMessage.showWarning( '请填写图片验证码', showTime );
      return;
    }
    sendMessage();
  } );
  $( '#img_validate .btn-default' ).click( function() {
    $( '#img_verify_code' ).val( '' );
  } );
  //timer处理函数
  function SetRemainTime() {
    if ( curCount == 0 ) {
      window.clearInterval( InterValObj ); //停止计时器
      $( ".get-code" ).removeAttr( "disabled" ); //启用按钮
      $( ".get-code" ).css( 'background', '' );
      $( ".get-code" ).val( "重新获取验证码" );
    } else {
      curCount--;
      $( ".get-code" ).val( curCount + "s" );
    }
  }

  //设置Cookie
  function setCookie( name, value ) {
    var Days = 30;
    var exp = new Date();
    exp.setTime( exp.getTime() + Days * 24 * 60 * 60 * 1000 );
    document.cookie = name + "=" + escape( value ) + ";expires=" + exp.toGMTString();
  }
  //获取Cookie
  function getCookie( name ) {
    var arr, reg = new RegExp( "(^| )" + name + "=([^;]*)(;|$)" );
    if ( arr = document.cookie.match( reg ) )
      return unescape( arr[ 2 ] );
    else
      return null;
  }
  //清除Cookie
  function delCookie( name ) {
    var exp = new Date();
    exp.setTime( exp.getTime() - 1 );
    var cval = getCookie( name );
    if ( cval != null )
      document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
  }
  //删除所有cookie
  function clearCookie() {
    var keys = document.cookie.match( /[^ =;]+(?=\=)/g );
    if ( keys ) {
      for ( var i = keys.length; i--; )
        document.cookie = keys[ i ] + '=0;expires=' + new Date( 0 ).toUTCString()
    }
  }
  //中文字为2个字符
  function chkstrlen( str ) {
    var strlen = 0;
    for ( var i = 0; i < str.length; i++ ) {
      if ( str.charCodeAt( i ) > 255 ) {
        strlen += 2; //如果是汉字，则字符串长度加2
      } else {
        strlen++;
      }
    }
    return strlen;
  }
} );